package com.example.pcmonitor.controller;

import com.example.pcmonitor.server.WebSocketServer;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;


/**
 * WebSocketController
 * @author zhengkai.blog.csdn.net
 */
@Controller
public class DemoController {


    @RequestMapping("/")
    public String login(){
        return "login";
    }
    @RequestMapping("/index")
    public String index(){
        return "index";
    }

    @RequestMapping("/loginCheck")
    public String loginCheck(String username,String password, Model model, HttpServletRequest request){
        boolean flag=false;


        if("admin".equals(username)&&"123".equals(password)){
            return "redirect:/index";
        }else {
            model.addAttribute("msg","密码错误或者账号不存在");
            return "login";
        }
    }

    @RequestMapping("/push")
    @ResponseBody
    public ResponseEntity<String> pushToWeb() throws IOException {
        WebSocketServer.sendInfo("liaaa","1");
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }
}
